package #(package);

import net.cmkj.pm.common.anno.RequiresPermissions;
import com.jfinal.aop.Before;
import net.cmkj.pm.common.controller.BaseController;
import net.cmkj.pm.bean.#(className);

/**
 * #(className) controller
 * 控制器
 * 
 */
public class #(className)Controller extends BaseController {

	private final #(className)Service service = #(className)Service.service;
	
	/**
	 * 跳转至列表页
	 */
	@RequiresPermissions(value={"/#(classNameSmall)"})
	public void index() throws Exception {
		render("#(classNameSmall)List.html");
	}
	
	/**
	 * 跳转至对象添加修改页
	 */
	@RequiresPermissions(value={"/#(classNameSmall)"})
	public void form() throws Exception {
		Integer id= getParaToInt("id");
		if(id != null){
			setAttr("item", service.findById(id));
		}
		render("#(classNameSmall)Form.html");
	}
	
	/**
	 * 获取列表
	 */
	@RequiresPermissions(value={"/#(classNameSmall)"})
	public void getList() throws Exception {
		String name = getPara("name");
		Integer status = getParaToInt("status");
		renderJson(service.getList(getPage(), getRows(), name, status, getOrderbyStr()));
	}
	
	/**
	 * 对象保存
	 */
	@Before(#(className)Validator.class)
	@RequiresPermissions(value={"/#(classNameSmall)"})
	public void save() throws Exception {
		renderJson(service.save(getModel(#(className).class)));
	}

	/**
	 * 对象删除
	 */
	@RequiresPermissions(value={"/#(classNameSmall)"})
	public void delete() throws Exception {
		renderJson(service.deleteByIds(getPara("ids")));
	}
	
	/**
	 * 对象状态变更
	 */
	@RequiresPermissions(value={"/#(classNameSmall)"})
	public void setStatus() throws Exception {
		String ids = getPara("ids");
		Integer status = getParaToInt("status");
		renderJson(service.setStatus(ids, status));
	}
	
}